package com.bailiban.controller;

import com.bailiban.entity.Permission;
import com.bailiban.service.PermissionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zhulang
 * @Classname PermissionController
 * @Description PermissionController
 */
@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("findAll.do")
    public ModelAndView findAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "3") Integer size) {
        PageInfo<Permission> pageInfo = permissionService.findAll(page, size);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("permission-page-list");
        modelAndView.addObject("permissionList", pageInfo);
        return modelAndView;
    }

    @PostMapping("save")
    public String save(Permission permission) {
        Permission insert = permissionService.insert(permission);
        return "redirect:/permission/findAll.do";
    }
}
